'''
 爬虫处理业务
'''
import requests
from bs4 import BeautifulSoup

class pcScrawler():
    def __init__(self):
        self.headers={
            'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95'
        }
    #爬文本
    def getTargetText(self,url,selector):
        codes=requests.get(url,headers=self.headers).text
        bs = BeautifulSoup(codes,'html.parser')
        return [item.text for item in bs.select(selector=selector)]

    #爬图片
    def getTargetImg(self,imgurl):
        imgc = requests.get(imgurl).content
        with open("1.jpg",'wb') as f:
            f.write(imgc)
